/**
 * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package lumingweihua.future.cn.baselibgxh.base;

import android.app.Application;
import android.content.Context;
import android.text.TextUtils;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;

import lumingweihua.future.cn.baselibgxh.utils.ForceCloseHandler;
import lumingweihua.future.cn.baselibgxh.utils.SharedPreference;

/**
 * 
 * @author Administrator GXH
 *
 */
public class MyApplication extends Application {

    public static Context applicationContext;
    private static MyApplication instance;
    private String userToken;
    private String userId;
    private String city;
//    private
    
    @SuppressWarnings("unused")
    @Override
    public void onCreate() {

        super.onCreate();
        
        applicationContext = this;
      ForceCloseHandler.getInstance().init(applicationContext);
        instance = this;
        //imageLoader
        initImageLoader(getApplicationContext());
        
//        ShareSDK.initSDK(this);

        FutureApi.init(applicationContext);
        
        userToken = SharedPreference.getString(applicationContext, "userToken");
        userId = SharedPreference.getString(applicationContext, "userId");
    }

    public static MyApplication getInstance() {
        return instance;
    }
    
    public static void initImageLoader(Context context) {
        // This configuration tuning is custom. You can tune every option, you may tune some of them,
        // or you can create default configuration by
        //  ImageLoaderConfiguration.createDefault(this);
        // method.
        ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
        config.threadPriority(Thread.NORM_PRIORITY - 2)
        .denyCacheImageMultipleSizesInMemory()
        .diskCacheFileNameGenerator(new Md5FileNameGenerator())
                .diskCacheSize(1024 * 1024 * 1024)
        .memoryCacheExtraOptions(480, 800)
                .threadPoolSize(3)
        .denyCacheImageMultipleSizesInMemory()
//                .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
                .memoryCache(new WeakMemoryCache())
        .tasksProcessingOrder(QueueProcessingType.LIFO);
//      config.discCache(new UnlimitedDiskCache(cacheDir));//自定义缓存路�?
        // Initialize ImageLoader with configuration.
        ImageLoader.getInstance().init(config.build());
    }
    
    public String getUserToken() {
		return userToken;
	}

	public void setUserToken(String userToken) {
		this.userToken = userToken;
	}

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getCity() {
		return city;
//		return "广州";
	}

	public void setCity(String city) {
		this.city = city;
	}
	
	public boolean isUserLogin(){
		return !TextUtils.isEmpty(userToken);
	}

}
